/*** 
 * @_______________#########_______________________ 
 * @______________############_____________________ 
 * @______________#############____________________ 
 * @_____________##__###########___________________ 
 * @____________###__######_#####__________________ 
 * @____________###_#######___####_________________ 
 * @___________###__##########_####________________ 
 * @__________####__###########_####_______________ 
 * @________#####___###########__#####_____________ 
 * @_______######___###_########___#####___________ 
 * @_______#####___###___########___######_________ 
 * @______######___###__###########___######_______ 
 * @_____######___####_##############__######______ 
 * @____#######__#####################_#######_____ 
 * @____#######__##############################____ 
 * @___#######__######_#################_#######___ 
 * @___#######__######_######_#########___######___ 
 * @___#######____##__######___######_____######___ 
 * @___#######________######____#####_____#####____ 
 * @____######________#####_____#####_____####_____ 
 * @_____#####________####______#####_____###______ 
 * @______#####______;###________###______#________ 
 * @________##_______####________####______________ 
 * @
 * @Author: ipk518 18163976442@163.com
 * @Date: 2024-11-27 19:14:37
 * @LastEditors: ipk518 121206530@qq.com
 * @LastEditTime: 2025-01-22 14:44:03
 * @FilePath: /etws-sxk2307/src/main.cpp
 * @Description: 
 * @************佛祖保佑************
 * @Copyright (c) 2024 by etws@quyujiang, All Rights Reserved. 
 */

#include <stdio.h>
#include <iostream>
#include <stdlib.h>
#include <string.h>
#include "Server.h"
#include "Common.h"

using namespace std;

SystemState sysRunStatus = SYS_INIT;//系统初始化完成表示可处理数据标志
/**
 * @brief: 主函数
 * @param {int} argc
 * @param {char} *argv
 * @return {*}
 */
int main(int argc,char *argv[])
{
    auto exePath = executionPath();
	if (true == exePath.empty()) {
		printf("Can not locate execution path.\r\n");
        exit(-1);
    }

    string confFileVec[] = {
        exePath + "cfg/mylog.conf",
        exePath + "cfg/Config.ini"
    };
    if(isConfFileValid(confFileVec[0])) {
        my_logInit(confFileVec[0].c_str());
    } else {
        printf("Path:%s invalid!\r\n",confFileVec[0].c_str());
        exit(-2);
    }
    
    if(isConfFileValid(confFileVec[1])) {
        auto res = Conf::loadConf(confFileVec[1]);
        if ( !res.isOk() ) {
            printf("%s \r\n",res.message().c_str());
            printf("Conf init failure!");
            exit(-3);
        }
    } else {
        printf("Path:%s invalid!\r\n",confFileVec[1].c_str());
        exit(-4);
    }
    bool ret = createFileDir(Conf::currentConf()->mFilePath.uAmplitudePath);
    if(!ret) {
        printf("Path:%s invalid!\r\n",Conf::currentConf()->mFilePath.uAmplitudePath.c_str());
        exit(-5); 
    }
    ret = createFileDir(Conf::currentConf()->mFilePath.uFreqPointPath);
    if(!ret) {
        printf("Path:%s invalid!\r\n",Conf::currentConf()->mFilePath.uFreqPointPath.c_str());
        exit(-5); 
    }
    ret = createFileDir(Conf::currentConf()->mFilePath.uFreqReferencePath);
    if(!ret) {
        printf("Path:%s invalid!\r\n",Conf::currentConf()->mFilePath.uFreqReferencePath.c_str());
        exit(-5); 
    }
    
    Server::Instance().m_configPath = confFileVec[1];//配置文件路径
    if (-1 == Server::Instance().init()) {
        printf("Server error.\r\n");
        fprintf(stderr, "Server error.\n");
        exit(-5);
    }

    Server::Instance().run();

    return 0;
}